import sqlite3
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import numpy as np

firstdb = sqlite3.connect("news.db")

str = ''
# 查询语句
query_sql = "select keywords from news_info where username='王云鹏'"
for result in firstdb.execute(query_sql):
    str += result[0]

print(str)
x, y = np.ogrid[:300, :300]
mask = (x - 150) ** 2 + (y - 150) ** 2 > 130 ** 2
mask = 255 * mask.astype(int)
wc = WordCloud(background_color="white", repeat=True, mask=mask)
wc.generate(str)

plt.axis("off")
plt.imshow(wc, interpolation="bilinear")
plt.show()

